package zuo.algo.util;

import java.util.Random;

public class SortUtils {

    public static void swap(int[] arr, int i, int j) {
        int temp = arr[i];
        arr[i] = arr[j];
        arr[j] = temp;
    }

    public static int[] getRandomArr(int maxLen) {
        int maxVal = 100000;
        return getRandomArr(maxLen, maxVal);
    }

    public static int[] getRandomArr(int maxLen, int maxVal) {
        Random random = new Random();
        int realLen = random.nextInt(maxLen) + 1;
        int[] arr = new int[realLen];
        for (int i = 0; i < realLen; i++) {
            arr[i] = random.nextInt(maxVal);
        }
        return arr;
    }

    public static void assertArr(int[] arr1, int[] arr2) {
        int len = arr1.length;
        for (int i = 0; i < len; i++) {
            if (arr1[i] != arr2[i]) {
                printArr(arr1);
                printArr(arr2);
                throw new RuntimeException();
            }
        }
    }

    public static void assertArr(int[] arr1, Object[] arr2) {
        int len = arr1.length;
        for (int i = 0; i < len; i++) {
            if (arr1[i] != (Integer) arr2[i]) {
                printArr(arr1);
                printArr(arr2);
                throw new RuntimeException();
            }
        }
    }


    public static void printArr(int[] arr) {
        for (int i : arr) {
            System.out.print(i + " ");
        }
        System.out.println();
    }

    public static void printArr(Object[] arr) {
        for (Object i : arr) {
            System.out.print(i + " ");
        }
        System.out.println();
    }
}
